package com.gsnd.gsnd22estore.web.controller;


import com.gsnd.gsnd22estore.domain.EsUser;
import com.gsnd.gsnd22estore.dto.*;
import com.gsnd.gsnd22estore.result.Result;
import com.gsnd.gsnd22estore.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping("/login")
    public Result<LoginReturnDTO> login(@RequestBody UserLoginDTO userLogin){
        return Result.success(userService.userLogin(userLogin));
    }

    @GetMapping("/getUserInfo")
    public Result<UserDTO> getUserInfo(HttpServletRequest request){
        return Result.success(userService.getUserInfo(request));
    }

    @PostMapping("/register")
    public Result<String> register(@RequestBody UserRegisterDTO userRegisterDTO){
        userService.userRegister(userRegisterDTO);
        return Result.success("恭喜注册成功！");
    }
    @PutMapping("/updatePassword")
    public Result<String> updatePassword(UpdatePasswordDTO updatePasswordDTO,HttpServletRequest request){
        Integer userId=Integer.parseInt((String)request.getAttribute("userId"));
        return Result.success("更改密码成功！");
    }
    @PostMapping("/updateUser")
    public Result<String> updateUser(@RequestBody UpdateUserDTO updateUserDTO){
        userService.updateUser(updateUserDTO);
        return Result.success("用户信息修改成功！");
    }
//    @PostMapping("/updateUser")
//    public Result<String> updateUser(){
//            return Result.success();
//
//    }
}
